package com.century.sjt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.century.sjt.R;
import com.century.sjt.entity.MyOrderInfo;

import java.util.List;

/**
 * @author:周玲波
 * @Description: 我的订单适配器
 * @date : 2016/8/29 20:33
 */
public class MyOrderAdapter extends BaseAdapter {
    Context mContext;
    List<MyOrderInfo> mList;
    LayoutInflater inflater;

    public MyOrderAdapter(Context mContext, List<MyOrderInfo> mList) {
        this.mContext = mContext;
        this.mList = mList;
        inflater = LayoutInflater.from(mContext);


    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.sjt_myorder_lv_item,null);
            holder.tv_order_id= (TextView) convertView.findViewById(R.id.tv_order_id);
            holder.tv_order_time= (TextView) convertView.findViewById(R.id.tv_order_time);
            holder.tv_order_amount= (TextView) convertView.findViewById(R.id.tv_order_amount);
            holder.tv_order_money= (TextView) convertView.findViewById(R.id.tv_order_money);
            holder.tv_currency_type= (TextView) convertView.findViewById(R.id.tv_currency_type);
            //holder.tv_order_status= (TextView) convertView.findViewById(R.id.tv_order_status);
            holder.iv_goods_icon= (ImageView) convertView.findViewById(R.id.iv_goods_icon);
            holder.tv_shop_name= (TextView) convertView.findViewById(R.id.tv_shop_name);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tv_shop_name.setText(mContext.getResources().getString(R.string.text_shop_name));

        holder.tv_order_id.setText(mList.get(position).getShopName());
        holder.tv_order_time.setText(mList.get(position).getDate());
        holder.tv_order_amount.setText(mList.get(position).getGoodsQuantity());
        holder.tv_order_money.setText(mList.get(position).getOrderAmount());
        //holder.tv_currency_type.setText(mList.get(position).getOrderCurrency());
//        if(mList.get(position).getStatusName().equals("null")){
//            holder.tv_order_status.setText("");
//        }else{
//            holder.tv_order_status.setText(mList.get(position).getStatusName());
//        }


//        Log.e("img",mList.get(position).getImage());
        Glide.with(mContext).load(mList.get(position).getImage()).into(holder.iv_goods_icon);
        return convertView;
    }

    class ViewHolder {
        TextView tv_order_id;
        TextView tv_order_time;
        TextView tv_order_amount;
        TextView tv_order_money;
        TextView tv_currency_type;
        TextView tv_order_status;
        TextView tv_shop_name;
        ImageView iv_goods_icon;

    }
}
